﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RPGProject;

namespace RPGProject.GameWorld.GameObjects
{
    /// <summary>
    /// A player character.
    /// </summary>
    class Player : Character
    {
        public Player(int x, int y, String name, World world)
            : base(x, y, Constants.GetInstance()["Player.MaxHP"], 'P', ConsoleColor.Yellow, name, world, "player")
        {
        }
        /// <summary>
        /// Listens to a GameObjectEvent, from Character.
        /// </summary>
        /// <param name="e">The event to listen to.</param>
        /// <returns>An event if needed.</returns>
        public override GameObjectEvent Listen(GameObjectEvent e)
        {
            if(e.Name == "collision" && e.Has("source") && e["source"] == this)
            {
                // if this is the source of the collision to a GameObject
                // attempts to attack it.
                GameObject target = (GameObject)e["target"];
                if (target is Character)
                {
                    GameObjectEvent ge = this.GetDamageEvent();
                    ge["target"] = target;
                    ge["damage"] = Constants.GetInstance()["Player.MeleeDamage"];
                    this.world.Listen(ge);
                    return null;
                }
            }
            return base.Listen(e);
        }



    }
}
